(旧Siv3D) 引き出し線を描く
https://gyazo.com/386b69c379ea9e910965131121ef4ae0
code:leadline.cpp
enum class LeadLineTextHAlign
{
Left,
Right,
};
enum class LeadLineTextVAlign
{
Top,
Middle,
Bottom,
};
void drawLeadLine(const Vec2& from, const Circular& lead1, const double lead2, const String text, const LeadLineTextHAlign halign, const LeadLineTextVAlign valign, const Font& font)
{
const Vec2 p1 = from;
const Vec2 p2 = p1 + lead1;
const Vec2 p3 = p2 + Circular(lead2, halign == LeadLineTextHAlign::Left ? 270_deg : 90_deg);
const Rect region = font(text).region();
Vec2 pText;
pText.x = halign == LeadLineTextHAlign::Left ? p3.x : p3.x - region.w;
switch (valign)
{
case LeadLineTextVAlign::Top: pText.y = p3.y - region.h; break;
case LeadLineTextVAlign::Middle: pText.y = p3.y - region.h / 2; break;
case LeadLineTextVAlign::Bottom: pText.y = p3.y; break;
}
Line(p1, p2).draw(Palette::White);
Line(p2, p3).draw(Palette::White);
font(text).draw(pText, Palette::White);
}
void Main()
{
Graphics::SetBackground(Palette::Black);
const Font font(12);
while (System::Update())
{
Circle(Window::Center(), 50.0).draw(Palette::Darkorange);
drawLeadLine(Window::Center(), Circular(100.0, 60_deg), 150.0, L"引き出し線", LeadLineTextHAlign::Right, LeadLineTextVAlign::Top, font);
drawLeadLine(Window::Center() + Circular(50.0, -45_deg), Circular(100.0, -45_deg), 150.0, L"左にも引ける", LeadLineTextHAlign::Left, LeadLineTextVAlign::Top, font);
}
}